import React, { Component } from 'react'

export default class Cat extends Component {
  constructor () {
    super()

    this.state = {
      position: {
        x: 0,
        y: 0
      }
    }
  }

  move = e => {
    this.setState({
      position: {
        x: e.clientX,
        y: e.clientY
      }
    })
  }

  componentDidMount () {
    window.addEventListener('mousemove', this.move)
  }

  componentWillUnmount () {
    window.removeEventListener('mousemove', this.move)
  }

  render () {
    return (
      <div>
        <img
          src='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F68be3197-8ff9-4316-9b60-b5ce186cef99%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1691831642&t=7c78d6b9091f5210b5d2891a737f2b17'
          style={{
            width: 100,
            height: 100,
            position: 'absolute',
            left: this.state.position.x,
            top: this.state.position.y
          }}
          alt=''
        />
      </div>
    )
  }
}
